package com.alibaba.it.asset.codegen.db2entity;

import com.google.common.collect.Maps;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lwf on 14-7-26.
 */
public class GenerateContext {
    private boolean overwrite = false;
    private String genPath;
    private String entityPackage;
    private String repositoryPackage;
    private String servicePackage;
    private String vmPath;
    private Map<String, Object> paramMap = new HashMap<String, Object>();

    private GenerateContext(Builder builder) {
        genPath = builder.genPath;
        overwrite = builder.overwrite;
        entityPackage = builder.entityPackage;
        repositoryPackage = builder.repositoryPackage;
        servicePackage = builder.servicePackage;
        vmPath = builder.vmPath;
        paramMap = builder.paramMap;
    }

    public Map<String, Object> toMap() {
        Map<String, Object> map = Maps.newHashMap();
        if (paramMap != null) {
            map.putAll(paramMap);
        }
        map.put("genPath", genPath);
        map.put("overwrite", overwrite);
        map.put("entityPackage", entityPackage);
        map.put("repositoryPackage", repositoryPackage);
        map.put("servicePackage", servicePackage);
        map.put("vmPath", vmPath);
        return map;
    }

    public String getGenPath() {
        return genPath;
    }

    public String getEntityPackage() {
        return entityPackage;
    }

    public String getRepositoryPackage() {
        return repositoryPackage;
    }

    public String getServicePackage() {
        return servicePackage;
    }

    public boolean getOverwrite() {
        return overwrite;
    }

    public String getVmPath() {
        return vmPath;
    }

    public Map<String, Object> getParamMap() {
        return paramMap;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public static final class Builder {
        private String genPath;
        private boolean overwrite = false;
        private String entityPackage;
        private String repositoryPackage;
        private String servicePackage;
        private String vmPath;
        private Map<String, Object> paramMap;

        private Builder() {
        }

        public Builder genPath(String genPath) {
            this.genPath = genPath;
            return this;
        }

        public Builder overwrite(boolean overwrite) {
            this.overwrite = overwrite;
            return this;
        }

        public Builder entityPackage(String entityPackage) {
            this.entityPackage = entityPackage;
            return this;
        }

        public Builder repositoryPackage(String repositoryPackage) {
            this.repositoryPackage = repositoryPackage;
            return this;
        }

        public Builder servicePackage(String servicePackage) {
            this.servicePackage = servicePackage;
            return this;
        }

        public Builder vmPath(String vmPath) {
            this.vmPath = vmPath;
            return this;
        }

        public Builder paramMap(Map<String, Object> paramMap) {
            this.paramMap = paramMap;
            return this;
        }

        public Builder setParam(String key, Object val) {
            if (paramMap == null) {
                paramMap = Maps.newHashMap();
            }
            paramMap.put(key, val);
            return this;
        }

        public GenerateContext build() {
            return new GenerateContext(this);
        }
    }
}
